#include<iostream>
#include<fstream>
#include<sstream>
#include<stdio.h>
#include<time.h>
#include<stdio.h>
#include<time.h>
#include<arm_neon.h>
const int col = 2700, row = 60000;
int n, m1, m2;
//n是一行中最多用到哪个int
using namespace std;
struct bitset {
	unsigned int bits[col];
	int lp = -1;
	void addNum(int num) {
		int n1 = num / 32, n2 = num % 32;
		bits[n1] += (0x80000000 >> n2);
		lp = max(lp, num);
		n = max(n, n1 + 1);
	}
};
bitset R[row], E[row];
void print(bitset& b, ofstream& of) {
	if (b.lp == -1) {
		of << endl;
		return;
	}
	for (int i = n; i >= 0; --i) {
		for (unsigned int temp = 1, j = 31; temp != 0; temp <<= 1, --j)
			if (temp & b.bits[i])
				of << i * 32 + j << " ";
	}
	of << endl;
}
void Xor(bitset& b1, bitset& b2) {
	int i = 0;
	for (; i + 4 <=n; i += 4)
	{
		uint32x4_t v1 = vld1q_u32(&b1.bits[i]);
		uint32x4_t v2 = vld1q_u32(&b2.bits[i]);
		uint32x4_t result= veorq_u32(v1,v2);
		vst1q_u32(&b1.bits[i], result);
	}
	for (; i<=n; ++i)b1.bits[i] ^= b2.bits[i];
	int k = n, j = 31;
	while (b1.bits[k] == 0 && k >= 0)--k;
	if (k < 0) {
		b1.lp = -1;
		return;
	}
	unsigned temp = 1;
	while ((b1.bits[k] & temp) == 0&&j>=0)temp <<= 1, --j;
	b1.lp = 32 * k + j;

}
void Gauss() {
	for (int i = 0; i < m2; ++i) {
		while (E[i].lp != -1) {
			if (R[E[i].lp].lp != -1) {
				Xor(E[i], R[E[i].lp]);
			}

			else {
				R[E[i].lp] = E[i];
				break;
			}
		}
	}
}
void readData() {
	fstream fs1("1.txt");
	string line;
	while (getline(fs1, line)) {
		stringstream ss(line);
		int index, num;
		ss >> index;
		R[index].addNum(index);
		while (ss >> num)
			R[index].addNum(num);
	}
	fs1.close();
	fs1.open("2.txt");
	while (getline(fs1, line)) {
		stringstream ss(line);
		int num;
		while (ss >> num)
			E[m2].addNum(num);
		++m2;
	}
	fs1.close();
}
int main() {
	readData();
	struct timespec sts,ets;
	timespec_get(&sts, TIME_UTC);
	Gauss();
	timespec_get(&ets, TIME_UTC);
	time_t dsec = ets.tv_sec - sts.tv_sec;
	long dnsec = ets.tv_nsec - sts.tv_nsec;
	if (dnsec < 0) {
		dsec--;
		dnsec += 1000000000ll;
	}

	ofstream of("output.txt");
	for (int i = 0; i < m2; ++i)
		print(E[i], of);
	of.close();
	ifstream if1("output.txt");
	ifstream if2("3.txt");
	int a=0, b=0, sum = 0;
	while (if1 >> a || if2 >> b) {
		sum += (a - b) * (a - b);
	}
	if1.close();
	if2.close();

	ofstream of_result("/home/s2011354/result.txt",ios::app);
	of_result << "neon gauss(golder) on nenon " <<endl;
	of_result <<"m2= "<<m2<<" time= "<< dsec << "." << dnsec << "s"<<endl;
	of_result.close();
}